package com.example.gradu.graduationproject.service.impl;

import com.example.gradu.graduationproject.domain.Directory;
import com.example.gradu.graduationproject.mapper.DirectoryMapper;
import com.example.gradu.graduationproject.service.DirectoryService;
import com.example.gradu.graduationproject.util.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (Directory)表服务实现类
 *
 * @author makejava
 * @since 2025-02-13 22:49:10
 */
@Service("directoryService")
public class DirectoryServiceImpl implements DirectoryService {
    @Resource
    private DirectoryMapper directoryMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param directoryid 主键
     * @return 实例对象
     */
    @Override
    public R queryById(Integer directoryid) {
        return R.ok().setData(this.directoryMapper.queryById(directoryid));
    }

    /**
     * 全查询
     *
     * @param directory 筛选条件
     * @return 查询结果
     */
    @Override
    public R queryAll(Directory directory) {
        return R.ok().setData(this.directoryMapper.queryAll(directory));
    }

    /**
     * 新增数据
     *
     * @param directory 实例对象
     * @return 实例对象
     */
    @Override
    public R insert(Directory directory) {
        this.directoryMapper.insert(directory);
        return R.ok().setData(directory);
    }

    /**
     * 修改数据
     *
     * @param directory 实例对象
     * @return 实例对象
     */
    @Override
    public R update(Directory directory) {
        this.directoryMapper.update(directory);
        return R.ok().setData(this.queryById(directory.getDirectoryid()));
    }

    /**
     * 通过主键删除数据
     *
     * @param directoryid 主键
     * @return 是否成功
     */
    @Override
    public R deleteById(Integer directoryid) {
        boolean del = this.directoryMapper.deleteById(directoryid) > 0;
        return R.ok().setData(del);
    }
}

